package com.mydemo.design_pattern.create_type.builder_pattern;

import java.util.ArrayList;
import java.util.List;

/**
 * <p></p >
 *
 * @author liming1
 * @version $Id: Meal, v1.0 2019-09-18 13:56 liming1 Exp $
 */
public class Meal {

    private List<Item> list = new ArrayList<>();

    public void setItem(Item item) {
        this.list.add(item);
    }

    public float getCost() {
        return list.stream().map(item -> item.price()).reduce(0F, (a, b) -> a + b).floatValue();
    }

    public void showItems(){
        for (Item item : list) {
            System.out.print("Item : "+item.name());
            System.out.print(", Packing : "+item.pack().pack());
            System.out.println(", Price : "+item.price());
        }
    }
}
